package com.cuotigou.util;

import cn.jiguang.common.resp.APIConnectionException;
import cn.jiguang.common.resp.APIRequestException;
import cn.jsms.api.JSMSClient;
import cn.jsms.api.SendSMSResult;
import cn.jsms.api.common.SMSClient;
import cn.jsms.api.common.model.SMSPayload;
import com.google.gson.JsonObject;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by yangweijian on 2018/7/17.
 */
public class MobileUtil {
    /**
     * 验证手机号格式
     */
    public static boolean isMobileNumber(String mobilenumber) {
        Pattern p = null;
        Matcher m = null;
        boolean b = false;
        p = Pattern.compile("^[1][3,4,5,7,8][0-9]{9}$");
        m = p.matcher(mobilenumber);
        b = m.matches();
        return b;
    }

    public static void main(String[] args) {

        SMSPayload payload = SMSPayload.newBuilder()
                .setMobileNumber("13758876025")
                .setTempId(1)
                .build();

        JsonObject json = new JsonObject();
        json.addProperty("mobile", "13758876025");
        json.addProperty("temp_id", 1);
        SMSClient client
                = new SMSClient(JSMSExample.masterSecret, JSMSExample.appkey);
        try {
            SendSMSResult res = client.sendSMSCode(payload);
            System.out.println("res:"+ res.toString());
        } catch (APIConnectionException e) {
            e.printStackTrace();
        } catch (APIRequestException e) {
            e.printStackTrace();
        }
    }

}
